package cn.outsourcing.supermarket.controller.backstage;

import cn.outsourcing.supermarket.common.Result;
import cn.outsourcing.supermarket.common.utils.ResultUtils;
import cn.outsourcing.supermarket.dto.OnlyIdPayloadDTO;
import cn.outsourcing.supermarket.dto.backstage.BackstageSpecificationSaveDTO;
import cn.outsourcing.supermarket.service.BackstageGoodsService;
import cn.outsourcing.supermarket.service.BackstageSpecificationService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 后台商品规格控制器
 *
 * @author gzkemays
 * @since 2021/11/3 23:47
 */
@RestController
@RequestMapping("/admin/specification")
public class SpecificationController {
  @Resource BackstageGoodsService backstageGoodsService;
  @Resource BackstageSpecificationService backstageSpecificationService;

  @PostMapping("/getGoodsSpec")
  public Result getGoodsSpec(@RequestBody OnlyIdPayloadDTO dto) {
    return ResultUtils.simpleResult(backstageGoodsService.getSpecData(dto));
  }

  @PostMapping("/detail")
  public Result getDetail(@RequestBody OnlyIdPayloadDTO dto) {
    return ResultUtils.simpleResult(backstageSpecificationService.getDetail(dto));
  }

  @PostMapping("/update")
  public Result update(@RequestBody BackstageSpecificationSaveDTO dto) {
    return ResultUtils.simpleResult(backstageSpecificationService.save(dto));
  }

  @PostMapping("/add")
  public Result add(@RequestBody BackstageSpecificationSaveDTO dto) {
    return ResultUtils.simpleResult(backstageSpecificationService.save(dto));
  }

  @PostMapping("/delete")
  public Result delete(@RequestBody OnlyIdPayloadDTO dto) {
    return ResultUtils.simpleResult(backstageSpecificationService.destroy(dto));
  }
}
